package org.patto.common.core.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author songchuanfu
 * @ClassName GlobalExceptionHandler
 * @qq 18050164315
 * @addres 1802284273@qq.com
 * @微信: wx-suagcf
 *
 * 全局捕获异常
 */
@Slf4j
@ControllerAdvice(basePackages = "org.patto")
public class GlobalExceptionHandler {
    /**
     * @return
     * @ControllerAdvice(basePackages = "org.patto") 扫包的范围
     * <p>
     * jar 需要拦截公司所以的项目
     * org.patto.main--- 主项目
     * org.patto.member--- 主项目
     */
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map<String, Object> errorResult(Exception e) {
        log.error("<error,e:{}>", e);
        Map<String, Object> errorResultMap = new HashMap<String, Object>();
        errorResultMap.put("code", "500");
        errorResultMap.put("msg", "系统出现错误!");
        return errorResultMap;
    }
}
